<?php
class Silk_Pms_Helper_Fileupload extends Mage_Core_Helper_Abstract{
	//参数：图片信息 保存路径
    //return:array
	public function upload($imagearr,$dir){
		$imagepath =array();
		$path="./media/pms/".$dir;
		if (!is_dir($path)){  
			mkdir(iconv("UTF-8", "GBK", $path),0777,true); 
		}
    	foreach ($imagearr as $key => $value) {
    		if(!$value["error"]){
    			if(in_array($value["type"],$this->type())){
    				$type = explode("/", $value["type"]);
    				$name = $this->proRandName().".".$type[1];
    			    move_uploaded_file($value["tmp_name"],$path.'/'.$name);
    			    $imagepath[$key]=$path.'/'.$name;
	    		}else{
	    			$imagepath[$key]=null;
	    		}     
    		}else{
    			$imagepath[$key]=null;
    	    }
    		
    	}
    	return $imagepath;
    }
    public function type(){
    	return array("image/jpg","image/jpeg","image/png");
    }
  	private function proRandName() {		
  		$fileName = date('YmdHis').rand(100,999);   	
  		return $fileName;
  	}
}
